package com.hnucm.house.ui.fragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Scroller;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hnucm.house.R;
import com.hnucm.house.adapter.NewHouseAdapter;
import com.hnucm.house.base.BaseFragment;
import com.hnucm.house.base.BasePresenter;
import com.hnucm.house.bean.NewHouseData;
import com.hnucm.house.contract.NewHouseCon;
import com.hnucm.house.presenter.NewHousePresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class NewHouseFragment extends BaseFragment<NewHouseCon.INewHouseView, NewHousePresenter> implements NewHouseCon.INewHouseView {

    private Context mContext;
    private List<NewHouseData.DataDTO> mList = new ArrayList<>();
    private NewHouseAdapter mAdapter;

    @BindView(R.id.new_house_recycler)
    RecyclerView mRecyclerView;

    @Override
    protected int getContentViewId() {
        return R.layout.fragment_new_house;
    }

    @Override
    protected void init() {
        mContext = getContext().getApplicationContext();
        initAdapter();
        mPresenter.loadNewHouse();
    }


    private void initAdapter() {
        GridLayoutManager manager = new GridLayoutManager(getContext(), 2);
        mRecyclerView.setLayoutManager(manager);
        mAdapter = new NewHouseAdapter(mList,getActivity());
        mRecyclerView.setAdapter(mAdapter);
    }

    @Override
    protected NewHousePresenter createPresenter() {
        return new NewHousePresenter();
    }

    @SuppressLint("NotifyDataSetChanged")
    @Override
    public void onLoadNewHouse(List<NewHouseData.DataDTO> dataDTOS) {
        mList.addAll(dataDTOS);
        mAdapter.setNewInstance(mList);
        System.out.println(mAdapter.getItemCount());
        //爷哭了，要notify啊，不然不显示
        mAdapter.notifyDataSetChanged();

    }

    @Override
    public void onRefreshNewHouse(List<NewHouseData.DataDTO> dataDTOS) {

    }
}
